/// <reference path="../../typings/lib.d.ts" />

import * as https from 'https'
import * as http from 'http'
import { ok } from 'assert'
import { test, testComplete } from 'moca'

(async function main() {
  await test("/github/profile", "should return profile", async function () {
    await new Promise((complete, fail) => {
      var req = require('http').request({
        hostname: '127.0.0.1',
        port: 8800,
        path: '/github/profile',
        headers: {
          'content-type': 'application/x-www-form-urlencoded',
          'content-length': Buffer.byteLength('accessToken=2b0d10ceac0fb79c6a155aba0f89af43f0e46ba3')
        }
      }, function (res: any) {
        var body = ''
        res.on('data', (d: any) => body += d)
        res.on('end', () => {
          try {
            var profile = JSON.parse(body)
            ok(typeof profile.id === 'number')
            ok(typeof profile.login === 'string')
            ok(profile.type === 'User')
            complete()
          } catch (e) {
            fail(e)
          }
        })
      })
      req.write('accessToken=2b0d10ceac0fb79c6a155aba0f89af43f0e46ba3')
      req.end()
    })
  });

  testComplete();
} ());


